﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Bonobo.Irc.Client.UI.Data
{
    [ValueConversion(typeof(object), typeof(String))]
    public class ServerResponseConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var message = (IrcMessage)value;

            switch (message.Type)
            {
                case IrcMessageType.ServerResponse:
                    return FormatServerResponse(message.Message);

                default:
                    return message.Message;
            }
        }

        private String FormatServerResponse(String message)
        {
            if (message[0] == ':')
            {
                message = message.Remove(0, message.IndexOf(' ') + 1);
            }
            message = message.Remove(0, message.IndexOf(' ') + 1);
            message = message.Remove(0, message.IndexOf(' ') + 1);
            if (message[0] == ':')
            {
                message = message.Remove(0, 1);
            }
            return message;
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
